﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using STT.Layer.Connection;
namespace STT.Profile.UserControls
{
    public partial class UcThoiKhoaBieu : System.Web.UI.UserControl
    {
        ToolBox tb = new ToolBox();
        STT.Business.BTbTKB a = new Business.BTbTKB();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindTKB();
            }
        }
        public DataTable datatkb()
        {
            DataTable tbl = a.SelectAll(Session["Mahv"].ToString());

            DataTable data = new DataTable();
            data.Columns.Add("NgayHoc", typeof(string));
            data.Columns.Add("Ca11", typeof(string));
            data.Columns.Add("Ca12", typeof(string));
            data.Columns.Add("Ca13", typeof(string));
            data.Columns.Add("Ca14", typeof(string));

            data.Columns.Add("Ca21", typeof(string));
            data.Columns.Add("Ca22", typeof(string));
            data.Columns.Add("Ca23", typeof(string));
            data.Columns.Add("Ca24", typeof(string));

            data.Columns.Add("Ca31", typeof(string));
            data.Columns.Add("Ca32", typeof(string));
            data.Columns.Add("Ca33", typeof(string));
            data.Columns.Add("Ca34", typeof(string));

            data.Columns.Add("Ca41", typeof(string));
            data.Columns.Add("Ca42", typeof(string));
            data.Columns.Add("Ca43", typeof(string));
            data.Columns.Add("Ca44", typeof(string));

            for (int i = 0; i <= tbl.Rows.Count - 1; i++)
            {

                DataRow empployee1 = data.NewRow();
                empployee1["NgayHoc"] = tbl.Rows[i][0].ToString().Trim();
                if (tbl.Rows[i][1].ToString().Trim() != "")
                {
                    string[] st = tbl.Rows[i][1].ToString().Trim().Split('|');
                    empployee1["Ca11"] = "Môn hoc : " + st[0].ToString();
                    empployee1["Ca12"] = "Giáo viên: " + st[1].ToString();
                    empployee1["Ca13"] = " Phòng học: " + st[2].ToString();
                    empployee1["Ca14"] = st[3].ToString();

                }
                else
                {
                    empployee1["Ca11"] = tbl.Rows[i][1].ToString();
                    empployee1["Ca12"] = tbl.Rows[i][1].ToString();
                    empployee1["Ca13"] = tbl.Rows[i][1].ToString();
                    empployee1["Ca14"] = tbl.Rows[i][1].ToString();
                }
                if (tbl.Rows[i][2].ToString().Trim() != "")
                {
                    string[] st1 = tbl.Rows[i][2].ToString().Trim().Split('|');
                    empployee1["Ca21"] = " Môn Học " + st1[0].ToString();
                    empployee1["Ca22"] = " Tên giáo viên " + st1[1].ToString();
                    empployee1["Ca23"] = " Phòng học" + st1[2].ToString();
                    empployee1["Ca24"] = st1[3].ToString();
                }
                else
                {
                    empployee1["Ca21"] = tbl.Rows[i][2].ToString().Trim();
                    empployee1["Ca22"] = tbl.Rows[i][2].ToString().Trim();
                    empployee1["Ca23"] = tbl.Rows[i][2].ToString().Trim();
                    empployee1["Ca24"] = tbl.Rows[i][2].ToString().Trim();
                }
                if (tbl.Rows[i][3].ToString().Trim() != "")
                {
                    string[] st2 = tbl.Rows[i][3].ToString().Trim().Split('|');

                    empployee1["Ca31"] = "Môn hoc : " + st2[0].ToString();
                    empployee1["Ca32"] = "Giáo viên: " + st2[1].ToString();
                    empployee1["Ca33"] = "Phòng học: " + st2[2].ToString();
                    empployee1["Ca34"] = st2[3].ToString();
                }
                else
                {
                    empployee1["Ca31"] = tbl.Rows[i][3].ToString().Trim();
                    empployee1["Ca32"] = tbl.Rows[i][3].ToString().Trim();
                    empployee1["Ca33"] = tbl.Rows[i][3].ToString().Trim();
                    empployee1["Ca34"] = tbl.Rows[i][3].ToString().Trim();
                }
                if (tbl.Rows[i][4].ToString().Trim() != "")
                {
                    string[] st3 = tbl.Rows[i][4].ToString().Trim().Split('|');
                    empployee1["Ca41"] = "Môn hoc : " + st3[0].ToString();
                    empployee1["Ca42"] = "Giáo viên: " + st3[1].ToString();
                    empployee1["Ca43"] = " Phòng học: " + st3[2].ToString();
                    empployee1["Ca44"] = st3[3].ToString();
                }
                else
                {
                    empployee1["Ca41"] = tbl.Rows[i][4].ToString().Trim();
                    empployee1["Ca42"] = tbl.Rows[i][4].ToString().Trim();
                    empployee1["Ca43"] = tbl.Rows[i][4].ToString().Trim();
                    empployee1["Ca44"] = tbl.Rows[i][4].ToString().Trim();
                }




                data.Rows.Add(empployee1);


            }
            return data;
        }


        private void BindTKB()
        {
            detail.DataSource = STT.Business.BTbTKB.TooltipTKB(Session["Mahv"].ToString());
            detail.DataBind();

            GridView1.DataSource = datatkb();
            GridView1.DataBind();

        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            BindTKB();
        }
    }
}